package com.puris.dao.teacher;

import com.puris.dao.BaseDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author Sonata
 * @data 2021/11/15 19:52
 */
public class ChangePwdDaoImpl implements ChangePwdDao {
    @Override
    public boolean changePassword(Connection connection, String id, String newPassword, String oldPassword) throws SQLException {
        PreparedStatement statement = null;

        if (connection != null) {
            String sql = "update teacher set password = ? where id = ? and password = ?";
            Object[] params = {newPassword, id, oldPassword};

            int rows = BaseDao.execute(connection, statement, sql, params);

            if (rows != 0) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
}
